﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using DigDes.DS2012.BaseLoader;

namespace DigDes.DS2012.DislocationLoader
{
    class Parser : BaseParser
    {
        public static Warp ParseData(string bufString, int currentYear)
        {
            var WarpData = new Warp();

            WarpData.CarNumber = SubString(bufString, 8, out bufString);
            WarpData.RollCheck = ConvertInt32(bufString, 1, out bufString);
            WarpData.Lightweight = ConvertInt32(bufString, 4, out bufString);
            WarpData.KindOfCar = ConvertInt32(bufString, 2, out bufString);
            WarpData.TypeOfConditionalCodeOfCar = ConvertInt32(bufString, 4, out bufString); 
            WarpData.StartDate = ConvertDate(bufString, 12, out bufString);

            WarpData.Unknown = false;
            bufString = bufString.Substring(1);

            WarpData.FeatTracking = ConvertInt32(bufString, 2, out bufString);
            WarpData.StateCode = ConvertInt32(bufString, 2, out bufString); 
            WarpData.ActualCargoWeight = ConvertInt32(bufString, 3, out bufString); 
            WarpData.ArrivalStation = ConvertInt32(bufString, 5, out bufString);
            WarpData.CargoRateCode = ConvertInt32(bufString, 5, out bufString); 
            WarpData.CargoOperativeCode = ConvertInt32(bufString, 2, out bufString);
            WarpData.RecipientCode = ConvertInt32(bufString, 4, out bufString);
            WarpData.SpecialNotesOfCar = SubString(bufString, 3, out bufString);
            WarpData.NumberOfCaseCG = ConvertInt32(bufString, 2, out bufString); 
            WarpData.NumberOfCaseCP = ConvertInt32(bufString, 2, out bufString);
            WarpData.NumberOfCaseKG = ConvertInt32(bufString, 2, out bufString);
            WarpData.NumberOfCaseKP = ConvertInt32(bufString, 2, out bufString);
            WarpData.ListNote = SubString(bufString, 6, out bufString);
            WarpData.CarParkType = ConvertInt32(bufString, 2, out bufString);
            WarpData.FaultCode = ConvertInt32(bufString, 1, out bufString);
            WarpData.DepartureStation = ConvertInt32(bufString, 5, out bufString);
            WarpData.OperationCode = ConvertInt32(bufString, 2, out bufString);
            WarpData.OperationDate = ConvertDate(bufString, 8, currentYear, out bufString);
            WarpData.StationOfOperation = ConvertInt32(bufString, 5, out bufString);
            WarpData.DeliveryRoad = ConvertInt32(bufString, 2, out bufString);
            WarpData.ReceptRoad = ConvertInt32(bufString, 2, out bufString);
            WarpData.TrainIndex = SubString(bufString, 13, out bufString);
            WarpData.TrainNumber = SubString(bufString, 4, out bufString);

            return WarpData;
        }
    }
}
